package com.sicong.common.core.utils;


import com.sicong.common.core.enums.ResultEnum;

/**
 * 统一返回信息工具类
 *
 * @author Chenww
 * @since 2020-09-18
 */
public class ResultUtil {

    public static <T> Result<T> success(T t) {
        return new Result<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), t);
    }

    public static <T> Result<T> success() {
        return new Result<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg());
    }

    public static <T> Result<T> error() {
        return new Result<>(ResultEnum.ERROR.getCode(),ResultEnum.ERROR.getMsg());
    }

    public static <T> Result<T> error(Exception e, ResultEnum resultEnum) {
        return new Result<>(resultEnum.getCode(), e.getMessage());
    }

    public static <T> Result<T> error(ResultEnum resultEnum) {
        return new Result<>(resultEnum.getCode(), resultEnum.getMsg());
    }

    public static <T> Result<T> error(String msg) {
        return new Result<>(ResultEnum.ERROR.getCode(), msg);
    }

    public static <T> Result<T> error(Integer code, String msg) {
        return new Result<>(code, msg);
    }

}
